TinyPortal

Development => Block Codes => Topic started by: JPDeni on October 28, 2006, 03:11:47 PM

Title: Fortune-teller block
Post by: JPDeni on October 28, 2006, 03:11:47 PM
Aku posted a Magic 8 Ball block (http://www.tinyportal.net/smf/index.php?topic=9338.0) snippet which is a wonderful addition to any site. Here's my take on something similar. It's not quite a spiffy in a lot of ways, but you can customize it to your heart's content and have it display in different languages.

This can go in either a php block or a php article, as you wish.

Step One
Copy the code below and save it in a file as Oracle.english.php. Put it in your Themes/default/languages folder.
<?php
$txt
['oracle_text'] = "Ask the Oracle a yes/no question";
$txt['oracle_submit'] = "Tell me the answer";
$txt['oracle_question'] = "Your question was";
$txt['oracle_response'] = "The Oracle says";

$txt['oracle'][] = "Signs point to yes. ";
$txt['oracle'][] = "Yes. ";
$txt['oracle'][] = "Without a doubt. ";
$txt['oracle'][] = "As I see it, yes. ";
$txt['oracle'][] = "You may rely on it. ";
$txt['oracle'][] = "It is decidedly so.";
$txt['oracle'][] = "Yes - definitely. ";
$txt['oracle'][] = "It is certain. ";
$txt['oracle'][] = "Most likely. ";
$txt['oracle'][] = "Outlook good. ";

$txt['oracle'][] = "My sources say no. ";
$txt['oracle'][] = "Outlook not so good. ";
$txt['oracle'][] = "Don't count on it.  ";
$txt['oracle'][] = "Very doubtful. ";
$txt['oracle'][] = "My reply is no. ";

$txt['oracle'][] = "Reply hazy, try again. ";
$txt['oracle'][] = "Concentrate and ask again. ";
$txt['oracle'][] = "Better not tell you now. ";
$txt['oracle'][] = "Cannot predict now. ";
$txt['oracle'][] = "Ask again later. ";

?>


These are the answers that were in the original Tyco Magic 8-Ball. You can add or subtract as many as you want and change them to suit your site. The first three texts are used for the display and are likely pretty obvious.

Step Two
Find or make an image that you want to use. I didn't post one here because I don't want to risk violating someone's copyright. You can use an 8-ball, a crystal ball, a gypsy fortune-teller, or whatever suits your site. Save the image as to the images folders of your installed themes. The downside is that you have to copy the image to all of the theme image folders. The upside is that you can have different images for different themes if you'd like. Just give them all the same name.

Step Three
Paste the following code into a php block or a php article:
global $settings,$txt;

loadLanguage('Oracle');
echo '<div style="text-align:center"><img src="',$settings['images_url'],'/oracle.jpg"><br />';
if (isset($_POST['get_answer']))
{
  if ($_POST['question'] <> '')
    $question= $_POST['question'];
  echo '<br />',$txt['oracle_question'],':<br />',stripslashes($question),'<br />';
  echo '<br />',$txt['oracle_response'],':<br />';
  $random = rand(0,(count($txt['oracle'])-1));
  $answer = $txt['oracle'][$random];
  echo $answer;
  echo '</div><br /><hr /><br />';
}

  $str = getenv("QUERY_STRING");
  if ($str)
    $action = 'index.php?'.$str;
  else
    $action = 'index.php';
  echo '<div style="text-align:center">',$txt['oracle_text'];
  echo '<form  action="',$action,'" method="post">';
  echo '<input type="hidden" name="get_answer" value="1">';
  echo '<input type="text" name="question" value="">';
  echo '<input type="submit" value="',$txt['oracle_submit'],'">';
  echo '</form></div>';

echo '</div>';


You can try it out on my site (http://site.jpdeni.com/index.php) (left side, second block down), but remember that my site is still under construction, so it's possible you may come at a moment when I've made some bonehead mistake and the whole site has crashed. If that's the case, come back in a few minutes and I'll probably have it fixed.  :uglystupid2:
Title: Re: Fortune-teller block
Post by: akulion on October 28, 2006, 03:28:08 PM
Quote
Brainiac says:
My reply is no

:( its all over for me :(

lol

Great snippet!!
Thanks :D
Title: Re: Fortune-teller block
Post by: JPDeni on October 28, 2006, 03:31:43 PM
Well, you know Brainiac is a villian, even though he's smart, so I'm not sure I'd be too disappointed. LOL

Thanks. Glad you like it. :)