View Full Version : fetch XML data to template?
mokujin
12-05-2012, 01:35 PM
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
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
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:
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:
<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 !!!
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.asp?filename=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 (https://vborg.vbsupport.ru/member.php?u=116367), kh99 (https://vborg.vbsupport.ru/member.php?u=346440)
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:
<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? :-(
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.
BirdOPrey5
12-16-2012, 06:15 PM
I know you PMed me but I also am not sure what the question is here... I guess I don't understand why you are using XML at all?
Maybe the question is just how to register the $mokusers array into the mokujin_users_bit template?
This is what I always refer back to- https://vborg.vbsupport.ru/showthread.php?t=228078
I believe you'd be using the "Save into a variable for later use in custom template" option.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.