vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=242)
-   -   [HOW TO - vB4] Rendering templates and registering variables - a short guide (https://vborg.vbsupport.ru/showthread.php?t=228078)

cellarius 04-04-2012 06:25 AM

Well, obviously $statar is an array. I have no idea how you set it up, but just as you can't do echo $array in PHP, you can't just use {vb:raw array}. In PHP you would do echo $array['key'] to output the value. In the template you need to use {vb:raw array.key} accordingly.

Just as described in the first chapter of the article.

Preech 04-05-2012 03:20 PM

Appreciate it Cellarius.
I looked through some of the other vbulletin, so I had to do something like.

while yada yada
{ something = something['']}

And everything started working. Mental error on my part. The only thing now is trying to complete a new mod for vbulletin.

Merriweather 04-22-2012 06:12 PM

If anyone is able to guide me, I am trying to hack the Post Thanks Plugin so I can pass a variable to a template as a conditional.

Here is the function I need to create a conditional for:

PHP Code:

function can_thank_this_post($postinfo = array(), $threadisdeleted 0$check_security false$securitytoken '')
{
    global 
$vbulletin;

    (
$hook vBulletinHook::fetch_hook('post_thanks_function_can_thank_this_post_start')) ? eval($hook) : false;

    if (
$postinfo['postid'] == || $vbulletin->userinfo['userid'] == || $postinfo['isdeleted'] || $threadisdeleted || (!($vbulletin->options['post_thanks_poster_button']) && $postinfo['userid'] == $vbulletin->userinfo['userid']))
    {
        return 
false;
    }

    if (
post_thanks_in_array($vbulletin->userinfo['usergroupid'], $vbulletin->options['post_thanks_usergroup_using']) || post_thanks_in_array($vbulletin->userinfo['userid'], $vbulletin->options['post_thanks_user_useing']))
    {
        return 
false;
    }

    if (
$vbulletin->userinfo['posts'] < $vbulletin->options['post_thanks_post_count_needed'])
    {
        return 
false;
    }

    if (
$vbulletin->options['post_thanks_max_per_day'])
    {
        global 
$count_thanks_so_far_totay;

        if (
$count_thanks_so_far_totay === null)
        {
            
$count_thanks_so_far_totay $vbulletin->db->query_first("SELECT COUNT(*) AS total FROM " .TABLE_PREFIX"post_thanks WHERE userid = " $vbulletin->userinfo['userid'] . " AND date > " . (TIMENOW - (60 60 24)) . "");
        }

        if (
$vbulletin->options['post_thanks_max_per_day'] <= $count_thanks_so_far_totay['total'])
        {
            return 
false;
        }
    }

    if (
$vbulletin->options['post_thanks_days_old'])
    {
        if (
TIMENOW > (($vbulletin->options['post_thanks_days_old'] * 60 60 24) + $postinfo['dateline']))
        {
            return 
false;
        }
    }

    if (
$vbulletin->options['post_groans_integrate'])
    {
        require_once(
DIR '/includes/functions_post_groans.php');
        if (
groaned_already($postinfo))
        {
            return 
false;
        }
    }

    if (
$check_security && function_exists(verify_security_token))
    {
        if (!
verify_security_token($securitytoken$vbulletin->userinfo['securitytoken_raw']))
        {
            return 
false;
        }
    }

    (
$hook vBulletinHook::fetch_hook('post_thanks_function_can_thank_this_post_end')) ? eval($hook) : false;

    return 
true;


And I want to be able to use:

HTML Code:

<vb:if condition="$post['can_thank_post']">Button code here</vb:if>

anupam_luv 04-24-2012 10:37 PM

LW (linkworth ) has given me a php file to include in the navigation bar. It will show rotating ads via rss feed. How can I include that file

I wrote the following code in global_start

PHP Code:


ob_start
();
  include(
'rss_reader.php');
  
$linkmura ob_get_contents();
ob_end_clean();

$templater vB_Template::create('mytemplate');
    
$templater->register('my_var'$linkmura);

$templatevalues['linkmura1'] = $templater->render();
vB_Template::preRegister('navbar'$templatevalues); 

And using {vb:raw linkmura1} to show that. But nothing is been shown (on navbar http://www.dstreetdirect.com )

Also the code in the rss_reader.php is :

PHP Code:


<?php
$insideitem 
false;
$tag "";
$title "";
$description "";
$link ""

function 
startElement($parser$name$attrs)
{
    global 
$insideitem$tag$title$description$link;

    if(
$insideitem)
    {
        
$tag $name;
    }
    elseif(
$name == "ITEM")
    {
        
$insideitem true;
    }
}

function 
endElement($parser$name)
{
    global 
$insideitem$tag$title$description$link;
   
    if (
$name == "ITEM")
    {
        
printf("<dt><b><a href='%s' title='%s'>%s</a></b></dt>",
        
trim($link),htmlspecialchars(trim($description)),htmlspecialchars(trim($title)));
        
printf("<dt>%s</dt><br/><br/>",htmlspecialchars(trim($description)));

        
$title "";
        
$description "";
        
$link "";
        
$insideitem false;
    }
}

function 
characterData($parser$data)
{
    global 
$insideitem$tag$title$description$link;

    if(
$insideitem)
    {
        switch(
$tag)
        {
            case 
"TITLE":
                
$title .= $data;
                break;
            case 
"LINK":
                
$link .= $data;
                break;
            case 
"DESCRIPTION";
                
$description .= $data;
                break;
        }
    }
}

$xml_parser xml_parser_create();
xml_set_element_handler($xml_parser"startElement""endElement");
xml_set_character_data_handler($xml_parser"characterData");

//====================================================================
//====================================================================
//====================================================================
// ENTER YOUR UNIQUE RSS URL BELOW WHERE YOU SEE THE XXXX's
//====================================================================
//====================================================================
//====================================================================
$fp fopen("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX""r")
   or die(
"Error reading RSS data.");


while (
$data fread($fp4096))
   
xml_parse($xml_parser$datafeof($fp))
      or die(
sprintf("XML error: %s at line %d",
         
xml_error_string(xml_get_error_code($xml_parser)),
         
xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);

?>

Please smbdy help and tell me easiest way to do that....

Dax IX 04-25-2012 12:33 AM

I'm just curious if registering the navbar is always necessary if you're creating a template for your own vB page, and if so, should the first post be updated to illustrate this?

And where the hell is the documentation on things like this:

Quote:

Originally Posted by Boofo (Post 2287132)
Try this in the parse_templates hook:

Code:

require_once(DIR . '/includes/class_template_parser.php');
$parser = new vB_TemplateParser('<div id="toplinks" class="toplinks">');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$find = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));

$parser = new vB_TemplateParser('<div style="float:right; margin: 5px -12px 5px 10px;">{vb:raw mycode}</div>');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$replace = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));

$vbulletin->templatecache['header'] = str_replace($find, $find . $replace, $vbulletin->templatecache['header']);
unset($find, $replace);


Or do you have to go through all the various files yourself to learn all of the functions and hope you stumble on what you're looking for?

Boofo 04-25-2012 02:14 PM

You won't stumble on to that anywhere in the files. ;)

Easy5s.net 04-28-2012 08:26 AM

Pls help me :(
https://vborg.vbsupport.ru/showthread.php?t=282142

Seductor 05-14-2012 10:52 PM

If I have this:
PHP Code:

$my_array = array(1,2); 

How can I render my template in order to show it? I don't know which key it is being used. If I do this:
Code:

{vb:raw my_array}
It is rendered like:
Code:

Array
PS: By the way, do you know any tutorial about how to send queries to the database from vBulletin?

BirdOPrey5 05-15-2012 12:41 AM

{vb:raw my_array.0} = 1
{vb:raw my_array.1} = 2

cellarius 05-15-2012 05:11 AM

Quote:

Originally Posted by Seductor (Post 2329431)
If I have this:
PHP Code:

$my_array = array(1,2); 

How can I render my template in order to show it? I don't know which key it is being used. If I do this:
Code:

{vb:raw my_array}
It is rendered like:
Code:

Array

See the article:
PHP Code:

{vb:raw my_var}
{
vb:raw my_array.key1

Quote:

PS: By the way, do you know any tutorial about how to send queries to the database from vBulletin?
https://vborg.vbsupport.ru/showthread.php?t=119350


All times are GMT. The time now is 02:04 AM.

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.01715 seconds
  • Memory Usage 1,813KB
  • 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
  • (5)bbcode_code_printable
  • (1)bbcode_html_printable
  • (6)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (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