Welcome to Geeklog, Anonymous Saturday, July 13 2024 @ 02:42 am EDT

Geeklog Forums

Fortune/Quote block


Ok, as lame as it is, I can't find the original source for the following, however its interesting none-the-less. When I dig up the URL for where I got the PHP code from, I'll post it in a comment. A random fortune or quote of the moment block is a nice addition to a page. First, you will need to take whichever fortune text files you want to use and combine them into a single quotefile in /path/to/geeklog. These are usually in /usr/share/games/fortune/. Add the following to system/lib-custom.php: //********************************************* function phpblock_randquote($infile = "/path/to/geeklog/quotefile", $delim = "\n%\n"Wink { // error trapping! if(!IsSet($infile)) { die ("You didn't specify a parameter for $infile!"Wink; } // attempt to open $infile if(!file_exists($infile)) { die ("$infile was not found! check your paths!"Wink; } else { $fp = fopen($infile, "r"Wink or die ("Error opening file!"Wink; } // okay, let's get going. $contents = fread($fp, filesize($infile)); $quote_arr = explode($delim,$contents); fclose($fp); // feed the Randomness Monster (tm) srand((double)microtime()*1000000); // generate random quote index $quote_index = (rand(1, sizeof($quote_arr)) - 1); // get quote at $quote_index and return it $herequote = $quote_arr[$quote_index]; return $herequote; } //********************************************* Now you'll need to create a PHP block that calls this function: phpblock_randquote. You don't need to specify variables in the block function itself, they are part of the function code in lib-custom.php. Voila!

Status: offline


Forum User
Registered: 01/22/02
Posts: 30
if you want to make a quick little hack, and are supremely confident that fortune is really that and not some crack program, then you can use this: function phpblock_fortune() { $fortune = `/usr/games/fortune`; return $fortune; } throw that in the bottom of your lib-custom.php and make a block. change the path to hit your fortune. probably a more legitimate solution would be to pull the quotes from a database, and have some sort of an admin tool for them. but that's verging on plugin capabilities....


I tried putting this on my geeklog 1.3.6 site and it made it so that no one could log in... you would put your login info in and it would only return you to the main page as if you wernt logged in!

All times are EDT. The time is now 02:42 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content