View Single Post
  #261  
Old 12-26-2012, 12:57 PM
acast acast is offline
 
Join Date: Aug 2008
Posts: 179
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01180 seconds
  • Memory Usage 1,811KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete