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.=" "; else $word_line.=$word[$x];
}
else
{
$word_line.="_<font size=1> </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 .= " 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]!!! 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.=" "; else $word_line.=$word[$x];
}
else
{
$word_line.="_<font size=1> </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 .= " 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]!!! 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.
|