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)

kh99 08-13-2012 11:21 PM

It could be because I had the code wrong - I fixed it in my post above. :o

PyroChixRock 08-13-2012 11:57 PM

Yay! that was it. I can't thank you enough. :D

Jonathan81 08-29-2012 01:06 PM

Quote:

Originally Posted by PyroChixRock (Post 2356515)
I have this little random banner code I've always used through the plugin system, but I can't seem to get it to work on vb4. Can anyone help?

normally, I call for it below the navbar with this...
Code:

<br>
<div style="text-align: center;">
$randombanner
</div>

and this for example, in the plugin area.
Code:

$path = '/forum/images/adbanners/';
$banners = array(
array( 'src' => 'imagine.jpg',
'href' => 'http://www.talkglass.com/'),
array( 'src' => 'waiting.jpg',
'href' => 'http://www.talkglass.com/),
);


$rnd = rand(0,count($banners)-1); // Pick a random array index.  They start with 0, so you have to -1.
$href = $banners[$rnd]['href'];  // Link HREF
$src = $path.$banners[$rnd]['src']; // Image source
$randombanner = '<a href="'.$href.'"><img border="0" src="'.$src.'" /></a>';

Where should i plug these in now for them to work with the built in ad system. it doesn't work using that.

Do you know how I can make the links open in a new window using the above code?

cellarius 08-29-2012 01:14 PM

It has nothing at all to do with the topic of this article, but:

Last line:
$randombanner = '<a href="'.$href.'" target="_blank"><img border="0" src="'.$src.'" /></a>';

Jonathan81 08-29-2012 01:22 PM

Quote:

Originally Posted by cellarius (Post 2360947)
It has nothing at all to do with the topic of this article, but:

Last line:
$randombanner = '<a href="'.$href.'" target="_blank"><img border="0" src="'.$src.'" /></a>';

Yes, I know, apologies...and thank you :)

soulz2003 10-16-2012 11:15 AM

The thing I am not understanding at this point is. If I am trying to preregister a variable for use with a stock template, in this case header. Where am I putting my code?

Is there a stock location to add this to or am I having to jump from adding a simple variable used on sites since vb 3.x into learning the basics of plugin writing? GLOBALS.permissions.pmquota isn't working for me in a new situation so I am trying to learn how to register permissions with the header template.

I believe the code is going to look like this?
Code:

$permissions = $vbulletin->userinfo['permissions'];
vB_Template::preRegister('header',array('permissions' => $permissions));

If so or even once correct where is this going? I mean were talking about a stock item for a stock template not a 3rd party plugin so I am confused.

Also is the above enough or do I need to add more like:
Code:

$permissions['pmquota'] = vb_number_format($vbulletin->userinfo['permissions']['pmquota']);

kh99 10-16-2012 08:03 PM

I answered in your other thread, but I'll answer more generally here: for the header, navbar, and footer templates I would recommend the hook parse_templates, since that's always executed just before those templates are rendered.

But the variable you want to use has to be available at that hook, and the timing of the call to the parse_templates hook can change. In the case of $permissions, that is set just after the global_start hook is called, so if some plugin using the global_start hook renders a template, parse_templates will be called but $permissions won't have been set yet so preRegistering it to a template won't work. (That's also why GLOBALS.permissions.pmquota stopped working - using preRegister() instead won't make any difference). But as I mentioned in the other thread, $permission is just a copy of $vbulletin->userinfo['permissions'], so if you use {vb:raw bbuserinfo.permissions.pmquota} in the template, that may work without any preRegistering.

TheSupportForum 10-17-2012 02:17 AM

is this possible

PHP Code:

$array = array($vbulletin->options['list1']); or array($vbulletin->options['list2']); 

i need to be able to use and array for 2 or more options, how can this be done

BirdOPrey5 10-21-2012 09:22 PM

As you wrote it, it is not going to work, you can't just put an "or" in the middle of any code.

I'm not really sure what your goal is or I'd give you an idea where to go... Maybe..

PHP Code:

$array = array(); //New array
$array[0] = $vbulletin->options['list1'];
if (
$vbulletin->options['list2']) // If list2 exists
  
$array[] = $vbulletin->options['list2']; 

That creates new array...

Assuming list1 always exists array[0] gets its value

Then If list2 exists the next element in array (array[1] in this case) gets the value of list2

acast 12-26-2012 12:57 PM

Hi, i am trying to learn how to adjust the plugins for v3 to v4.

Can anybody guide me and tell me what it's wrong?

Code working in 3.6.6.

Code:

<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'hangman');
$globaltemplates = array(
        'hangman'
);
// pre-cache templates used by specific actions
$actiontemplates = array();


//vB Hangman 2.0 by Dr. Erwin Loh (Admin at vBulletin.org)
//Enjoy this hack!

require_once('./global.php');


$hangmanwords=&$vbulletin->options['hangmanwords'];
$hangmanmax=&$vbulletin->options['hangmanmax'];
$hangmanguests=&$vbulletin->options['hangmanguests'];



if ($hangmanguests==0) {
if (!$vbulletin->userinfo['userid']) {
print_no_permission();
 }
}
$vbulletin->input->clean_array_gpc('r', array(
        'letters' => TYPE_STR,
        'n' => TYPE_UINT
));
$letters = &$vbulletin->GPC['letters'];
$n = &$vbulletin->GPC['n'];
$additional_letters = " -.,;!?%&0123456789";       
$max=$hangmanmax;                                       
$hangmanwords = strtoupper($hangmanwords);
$words = explode(",",$hangmanwords);
$alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$all_letters=$letters.$additional_letters;
$wrong = 0;
srand((double)microtime()*1000000);
if (!isset($n)) {
$n = rand(1,count($words)-1);
}
$word_line="";
$word = $words[$n];
$done = 1;
for ($x=0; $x < strlen($word); $x++)
{
  if (strstr($all_letters, $word[$x]))
  {
    if ($word[$x]==" ") $word_line.="&nbsp; "; else $word_line.=$word[$x];
  }
  else
{
$word_line.="_<font size=1>&nbsp;</font>"; $done = 0; }
}
if (!$done)
{
  for ($c=0; $c<26; $c++)
  {
    if (strstr($letters, $alpha[$c]))
    {
      if (strstr($words[$n], $alpha[$c])) {
$links .= "\n<B>$alpha[$c]</B> ";
}
      else
{
$links .= "\n<FONT color=\"red\">$alpha[$c] </font>"; $wrong++;
}
    }
    else
    {
$links .= "\n<A HREF=\"$PHP_SELF?letters=$alpha[$c]$letters&n=$n\">$alpha[$c]</A> "; }
  }
  $nwrong=$wrong;
  if ($wrong >= $max)
  {
$n = rand (1,count($words)-1);
    if ($n>(count($words)-1)) $n=0;
    $sorry .= "<BR><BR><H1><font size=5>\n$word_line</font></H1>\n<p><BR><FONT color=\"red\"><BIG>SORRY, YOU ARE HANGED!!!</BIG></FONT><BR><BR>";
    if (strstr($word, " ")) $term="phrase"; else $term="word";
    $play .= "The $term was \"<B>$word</B>\"<BR><BR>\n<A HREF=$PHP_SELF?n=$n>Play again.</A>\n\n";
  }
  else
  {
    $guess .= " &nbsp; Number of Wrong Guesses Left: <B>".($max-$wrong)."</B><BR>\n<H1><font size=5>\n$word_line</font></H1>\n<P><BR>Choose a letter:<BR><BR>\n$links\n";
  }
}
else
{
$n = rand (1,count($words)-1);
  if ($n>(count($words)-1)) $n=0;
  $win .= "<BR><BR><H1><font size=5>\n$word_line</font></H1>\n<P><BR><BR><B>Congratulations $bbuserinfo[username]!!! &nbsp;You have won!!!</B><BR><BR><BR>\n<A HREF=$PHP_SELF?n=$n>Play again</A>\n\n";
}
  $navbits = construct_navbits(array('' => $vbphrase['vb_hangman']));
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template(hangman) . '");');
?>

My modified code:
Code:

<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
ini_set("display_errors", 1);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'hangman');
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();
// get special data templates from the datastore
$specialtemplates = array();
$globaltemplates = array(
        'hangman'
);
// pre-cache templates used by specific actions
$actiontemplates = array();


//vB Hangman 2.0 by Dr. Erwin Loh (Admin at vBulletin.org)
//Enjoy this hack!

require_once('./global.php');


$hangmanwords=&$vbulletin->options['hangmanwords'];
$hangmanmax=&$vbulletin->options['hangmanmax'];
$hangmanguests=&$vbulletin->options['hangmanguests'];



if ($hangmanguests==0) {
if (!$vbulletin->userinfo['userid']) {
print_no_permission();
 }
}
$vbulletin->input->clean_array_gpc('r', array(
        'letters' => TYPE_STR,
        'n' => TYPE_UINT
));
$letters = &$vbulletin->GPC['letters'];
$n = &$vbulletin->GPC['n'];
$additional_letters = " -.,;!?%&0123456789";       
$max=$hangmanmax;                                       
$hangmanwords = strtoupper($hangmanwords);
$words = explode(",",$hangmanwords);
$alpha = "ABCDEFGHIJKLMN?OPQRSTUVWXYZ";
$all_letters=$letters.$additional_letters;
$wrong = 0;
srand((double)microtime()*1000000);
if (!isset($n)) {
$n = rand(1,count($words)-1);
}
$word_line="";
$word = $words[$n];
$done = 1;
for ($x=0; $x < strlen($word); $x++)
{
  if (strstr($all_letters, $word[$x]))
  {
    if ($word[$x]==" ") $word_line.="&nbsp; "; else $word_line.=$word[$x];
  }
  else
{
$word_line.="_<font size=1>&nbsp;</font>"; $done = 0; }
}
if (!$done)
{
  for ($c=0; $c<26; $c++)
  {
    if (strstr($letters, $alpha[$c]))
    {
      if (strstr($words[$n], $alpha[$c])) {
$links .= "\n<B>$alpha[$c]</B> ";
}
      else
{
$links .= "\n<FONT color=\"red\">$alpha[$c] </font>"; $wrong++;
}
    }
    else
    {
$links .= "\n<A HREF=\"$PHP_SELF?letters=$alpha[$c]$letters&n=$n\">$alpha[$c]</A> "; }
  }
  $nwrong=$wrong;
  if ($wrong >= $max)
  {
$n = rand (1,count($words)-1);
    if ($n>(count($words)-1)) $n=0;
    $sorry .= "<BR><BR><H1><font size=5>\n$word_line</font></H1>\n<p><BR><FONT color=\"red\"><BIG>SORRY, YOU ARE HANGED!!!</BIG></FONT><BR><BR>";
    if (strstr($word, " ")) $term="phrase"; else $term="word";
    $play .= "The $term was \"<B>$word</B>\"<BR><BR>\n<A HREF=$PHP_SELF?n=$n>Play again.</A>\n\n";
  }
  else
  {
    $guess .= " &nbsp; Number of Wrong Guesses Left: <B>".($max-$wrong)."</B><BR>\n<H1><font size=5>\n$word_line</font></H1>\n<P><BR>Choose a letter:<BR><BR>\n$links\n";
  }
}
else
{
$n = rand (1,count($words)-1);
  if ($n>(count($words)-1)) $n=0;
  $win .= "<BR><BR><H1><font size=5>\n$word_line</font></H1>\n<P><BR><BR><B>Congratulations $bbuserinfo[username]!!! &nbsp;You have won!!!</B><BR><BR><BR>\n<A HREF=$PHP_SELF?n=$n>Play again</A>\n\n";
}
$navbits = construct_navbits(array('' => $vbphrase['vb_hangman']));
$navbar = render_navbar_template($navbits);
// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle = 'hangman';
// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######
$templater = vB_Template::create('hangman');
$templater->register_page_templates();
$templater->register('hangmanwords', $hangmanwords);
$templater->register('hangmanmax', $hangmanmax);
$templater->register('hangmanguests', $hangmanguests);
$templater->register('letters', $letters);
$templater->register('n', $n);
$templater->register('additional_letters', $additional_letters);
$templater->register('words', $words);
$templater->register('alpha', $alpha);
$templater->register('all_letters', $all_letters);
$templater->register('wrong', $wrong);
$templater->register('word', $word);
$templater->register('done', $done);
$templater->register('word_line', $word_line);
$templater->register('c', $c);
$templater->register('links', $links);
$templater->register('max', $max);
$templater->register('x', $x);
$templater->register('sorry', $sorry);
$templater->register('play', $play);
$templater->register('win', $win);
$templater->register('term', $term);
$templater->register('guess', $guess);
$templater->register('nwrong', $nwrong);
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
print_output($templater->render());
?>

It doesn't work, and i don't know why. I tried with several plugins but no one works. Thanks for your help.


All times are GMT. The time now is 05:57 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.02336 seconds
  • Memory Usage 1,804KB
  • 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
  • (6)bbcode_code_printable
  • (2)bbcode_php_printable
  • (2)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