TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

May 18, 2024, 10:02:17 AM

Login with username, password and session length
Members
  • Total Members: 3,886
  • Latest: Grendor
Stats
  • Total Posts: 195,189
  • Total Topics: 21,220
  • Online today: 112
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 50
  • Total: 50

Fortune-teller block

Started by JPDeni, October 28, 2006, 03:11:47 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JPDeni

Aku posted a Magic 8 Ball block 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 (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:

akulion

Quote
Brainiac says:
My reply is no

:( its all over for me :(

lol

Great snippet!!
Thanks :D

JPDeni

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. :)