vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   fetch XML data to template? (https://vborg.vbsupport.ru/showthread.php?t=292671)

mokujin 12-05-2012 01:35 PM

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

kh99 12-05-2012 02:02 PM

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?

mokujin 12-05-2012 02:20 PM

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

kh99 12-05-2012 02:38 PM

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.

mokujin 12-05-2012 03:28 PM

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 !!!

kh99 12-05-2012 03:54 PM

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?

mokujin 12-05-2012 05:06 PM

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,

mokujin 12-14-2012 11:08 PM

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!!!!

mokujin 12-16-2012 02:24 PM

No one? :-(

kh99 12-16-2012 02:42 PM

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.


All times are GMT. The time now is 12:06 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.01241 seconds
  • Memory Usage 1,757KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_html_printable
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete