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

Reply
 
Thread Tools Display Modes
  #1  
Old 12-05-2012, 01:35 PM
mokujin's Avatar
mokujin mokujin is offline
 
Join Date: Oct 2005
Location: Czech
Posts: 345
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default fetch XML data to template?

hello,
i have a question and need your help,
how can I fetch data from XML file to template?

If I know, when I reply to a thread that is callback via XML?

Thank you
Reply With Quote
  #2  
Old 12-05-2012, 02:02 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm not sure what you're asking. Do you have php code reading an xml file, and you want to insert that into a template?
Reply With Quote
  #3  
Old 12-05-2012, 02:20 PM
mokujin's Avatar
mokujin mokujin is offline
 
Join Date: Oct 2005
Location: Czech
Posts: 345
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes exaclty!

I know how to create vbb XML group (file ajax.php: starting at line 123)
but I want to insert them to a template :-)

Do you have any experience (or have a tutorial somewhere)?

Thank u
Reply With Quote
  #4  
Old 12-05-2012, 02:38 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't have any experience with it, but if you're using one of the vb classes to build xml output (like is done in ajax.php to return xml), you can call fetch_xml() to get a string instead of calling print_xml(). Then you can use that in a template like you would any other string.
Reply With Quote
  #5  
Old 12-05-2012, 03:28 PM
mokujin's Avatar
mokujin mokujin is offline
 
Join Date: Oct 2005
Location: Czech
Posts: 345
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I dont have it yet,
here is example php misc_start hook:
PHP Code:
if ($_REQUEST['do'] == 'xml')
{
require_once 
DIR '/includes/class_xml.php';
    
$xml = new vB_AJAX_XML_Builder($vbulletin'text/xml');
    
$xml->add_group('users');

        
$users $db->query_read_slave("
            SELECT user.userid, user.username FROM " 
TABLE_PREFIX "user AS user
            ORDER BY username
            LIMIT 15
        "
);
        while (
$user $db->fetch_array($users))
        {
            
$xml->add_tag('user'$user['username'], array('userid' => $user['userid']));
        }

    
$xml->close_group();
    
$xml->print_xml();

And then you browse http://localhost/upload/misc.php?do=xml
You have:
Code:
<users><user userid="1">admin</user><user userid="5">newregister</user><user userid="4">nicktest</user><user userid="6">testreg</user><user userid="3">testregister</user><user userid="2">user</user></users>
I dont know how to fetch them to a template (lets call it template_xml_users )

Thanks !!!
Reply With Quote
  #6  
Old 12-05-2012, 03:54 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry, I'm still not exactly sure what you want to do. ajax.php actually returns some html (which in a way can be thought of as xml), and the javascript uses it to set the innerHTML property of an element. I suppose there isn't any reason that you couldn't return <user> or other custom tags, but then you'd need to process it using javascript. It's probably easier to format it as html (using templates if you want) if that's how you're planning to display it.

Maybe I'm still missing the point of what you're doing. If you want to make a plugin that returns user data as xml, that's fine, but it doesn't have anything to do with vbulletin templates. How do you want http://localhost/upload/misc.php?do=xml to be used? What is going to request that data?
Reply With Quote
  #7  
Old 12-05-2012, 05:06 PM
mokujin's Avatar
mokujin mokujin is offline
 
Join Date: Oct 2005
Location: Czech
Posts: 345
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

http://localhost/upload/misc.php?do=xml is just an example of XML output.
I want to make some AJAX like here: http://www.w3schools.com/ajax/ajax_xmlfile.asp
But return all tags into vbb template.
Hmm, my English is not good enough
Please have a look here: http://www.w3schools.com/ajax/tryit....e=tryajax_xml2
You click Get CD info then you will have CDs info, but I want CDs info into templates

oof,
Reply With Quote
  #8  
Old 12-14-2012, 11:08 PM
mokujin's Avatar
mokujin mokujin is offline
 
Join Date: Oct 2005
Location: Czech
Posts: 345
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have this ajax code, it returns the usernames only, example: mokujin, kh99
Now what I need to do to return with userids: mokujin, kh99
PHP Code:
if ($_POST['do'] == 'users')
{
$vbulletin->input->clean_array_gpc('p', array('p' => UINT));

    
$xml = new vB_AJAX_XML_Builder($vbulletin'text/xml');
    
$xml->add_group('users');

        
$users $db->query_read_slave("
            SELECT user.userid, user.username FROM " 
TABLE_PREFIX "user
            AS user WHERE username LIKE('" 
$db->escape_string_like(mok) . "%')
            ORDER BY username
            LIMIT 15
        "
);
        while (
$user $db->fetch_array($users))
        {
            
$xml->add_tag('user'$user['username'], array('userid' => $user['userid']));
        }

    
$xml->close_group();
    
$xml->print_xml();
    

And my template mokujin_users_bit:
HTML Code:
<a href="member.php?u={vb:raw mokusers.userid}">{vb:raw mokusers.username}</a>
I want to fetch usernames into my template!
Please! Thank youuuuuu!!!!
Reply With Quote
  #9  
Old 12-16-2012, 02:24 PM
mokujin's Avatar
mokujin mokujin is offline
 
Join Date: Oct 2005
Location: Czech
Posts: 345
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No one? :-(
Reply With Quote
  #10  
Old 12-16-2012, 02:42 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, the template variables are replaced on the server before an html page is sent to the user's browser, so if what you want to do is to create a page that lists some users, you don't need to use ajax. You can build a string variable in php code, then register that to your template.

If you do have some reason to get the list using an ajax call from an html page (to avoid reloading the html page, for example), then what you need to do is process the returned xml using javascript, like is done in the example you linked to.

I'm still not sure which one of these you are trying to do.
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 01:00 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.04665 seconds
  • Memory Usage 2,269KB
  • 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)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (1)bbcode_html
  • (2)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
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (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
  • 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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete