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 04-12-2009, 01:32 AM
JonZ JonZ is offline
 
Join Date: Apr 2009
Posts: 33
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default help me to simplify my Quick Style Chooser mod

vB Version: 3.7.3
Here's a summary of what I am trying to achieve:

I am trying to make the Quick Style Chooser (QSC) to actually record the theme into the users profile. What is the Quick Style Chooser? it the drop down list that appear at the bottom of vB pages, which allow you to change your theme design on the fly. You can actually see an example of it at http://www.vbulletin.com/forum



What this chooser don't do however is it doesn't record the theme into the users profile and just query the actual webpage to adjust the choosen theme based on cookies, which is fine for anonymous users.

__________________________________________________ ____________________

What I did:

So I took the form in users Control Panel as a template, and take portions of code that would submit a selection the information based their values. On my HTML file, I put this html segment:

HTML Code:
<form action="/board/myprofile.php" method="post" >
     <input type="hidden" name="s" value="index.php" /> <!-- same path location where this form is executed -->
     <input type="hidden" name="do" value="updateoptions" />
     <input type="hidden" name="securitytoken" value="<?=$vbulletin->userinfo['securitytoken']?>" />
     <select class="forumselector" name="newstyleset" id="sel_newstyleset"  onchange="this.form.submit()";>
   	    <?=$quickchooserbits?>                 
     </select>
</form>
notice that I replaced the original onchange="switch_id( this, 'style')" by "this.form.submit()". So when a selection is made, the script automatically do a submit action and bring the user to myprofile.php.


__________________________________________________ __________________

My problems:

I don't have a great understanding in PHP, but I can solve many issues by improvisations.
Here what I did is I torn appart the original profile.php where the information of a submition was treated in the user CP.

PHP Code:
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT''myprofile');
define('CSRF_PROTECTION'true);

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');

// ############################### start update options ###############################
if ($_POST['do'] == 'updateoptions')
{
       
$web $_POST['s'];
    if (
$show['member']){
    
        
$vbulletin->input->clean_array_gpc('p', array('newstyleset'    => TYPE_INT));

        
$userdata =& datamanager_init('User'$vbulletinERRTYPE_STANDARD);
        
$userdata->set_existing($vbulletin->userinfo);

        
// style set
        
if ($vbulletin->options['allowchangestyles'] AND $vbulletin->userinfo['realstyleid'] != $vbulletin->GPC['newstyleset'])
        {
            
$userdata->set('styleid'$vbulletin->GPC['newstyleset']);
        }

        (
$hook vBulletinHook::fetch_hook('profile_updateoptions')) ? eval($hook) : false;
        
$userdata->save();
    }    
    else {
        
exec_header_redirect($web.'styleid');
    }    
}

// #############################################################################

exec_header_redirect('$web');

?>
The good news is, it working, almost. If I execute my html, choose an item from the dropdown list, it load myprofile.php, my theme change and the information is also changed in the user's profile (UCP). The bad news is, I haven't find a way to just change the theme based on cookies like the original QSC do for anonymous users, and I'm kinda stuck on this problem.

What the original QSC is doing to change the cookie's mode theme, is to get the value of a selected item, and paste it to the current address (ie: myweb.com/board/?styleid=45). You can try it on every board that support styles, take the web address and paste ?styleid=(styleid number here), you will browse temporarely on another theme. Where that query is being treated in the php files, I don't know.

The other problem, is the simplicity. I would like to not have an independent file (myprofile.php) to treat the transaction but in the html itself, just like the original QSC do. This way I could re-use the code on each new module without querying myprofile.php everytime, maybe in a form of a custom function. What I liked on the original QSC is I could just reuse the code in 3 lines, and that was it. This new one take 5-6 html lines, an independent file, and support codes for every page of my sites.

Also the problem with this code, is I have to specify a path with exec_header_redirect() function, when I just want to reload the same page I was before. Not very practical when I want to re-use this function on other pages.


____________________________


This is where I am stuck. I really hope you will help me to resolve this.
Please do many suggestions you can.


Thanks advance.

PS/ The QSC on this very board is working exactly the way I want. It change on the fly, AND it is saved in the user's profile. You can verify it yourself. Choose a color, log out, then log back in, the style you have choosen still apply.
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 12:28 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
  • Page Generation 0.03637 seconds
  • Memory Usage 2,250KB
  • Queries Executed 11 (?)
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)bbcode_html
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)showthread_list
  • (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_threadedmode.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_threaded
  • showthread_threaded_construct_link
  • 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