Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Random Quotes ?
has anyone tackled this ? adding a random text quote in vanilla
0
This discussion has been closed.
Comments
$Context->SetDefinition('RandomQuoteError','Cannot find the quotes file.'); // Path to the randomquotes text file $quotesPath = 'extensions/RandomQuotes'; // Name of the randomquotes text file $quotesSource = 'quotes.txt'; $GLOBAL["quotesPath"] = $quotesPath; $lineSeparator = "\n"; $quoteFile = fopen( implode("/", array ( $quotesPath, $quotesSource)), "r") or DIE($this->Context->GetDefinition('RandomQuoteError')); while (!feof($quoteFile)) { $quotesString .= fread($quoteFile, 1024); } // Here we split it into lines $quotes = explode( $lineSeparator, $quotesString); // And then randomly choose a line $chosen = $quotes[ mt_rand(0, count($quotes) - 1 ) ]; // This just echoes the chosen line, we'll position it later preg_match ( "/^([^:]+).(.*)/", $chosen, $matches); list ($nada, $quote ) = $matches; echo <<<EOF <div id=RandomQuotes> <table align=right> <tr> <td>$quote</td> </tr> </table> </div> EOF; ?>
It works, but I get the following error:
Notice: Undefined variable: quotesString in ..\extensions\RandomQuotes\default.php on line 24
I followed Mark's documentation and tried to understand how to give it a place under the forum title, but this far beyond my skills. For now it appears in the top right corner and displays random quote from a .txt file. I no idea how to make this a real extension (well, technically it is one, it appears in the setting panel, but... :B) I also can't see how to add the error message dictionary defintion.
So, if somebody could explain what to change to make it Vanilla compliant, it would be great
The good new is I don't get the notice anymore since I've put:
$quotesString = '';
above
while (!feof($quoteFile)) { $quotesString .= fread($quoteFile, 1024); }
Dunno if it's elegant or even correct, but it seems to work.
Since Pol seems to be in an extension-writing frenzy phase at the moment, I was wondering he could have a look at this...
I'd be pretty glad to have this finally working.
But would there be a way to display the quote somewhere in the forum header? Like under, above or instead of the forum title? Or maybe where notices and warnings are usually shown?
I also added a dictionary definition for the extension's title (Today's Quote by default) but for some reason beyond my skills, it didn't work for the panel version. I guess it has something to do with $Panel->AddString($quotedisplay, 180);, but I'm not sure how to handle this.