|
Cookbook /
RandomQuote-OldVersionGoalInsert a random quote into a wiki page. Solution
add the following line to config.php include_once("$farmD/cookbook/quote.php"); If your site doesn't use wikifarms, the correct include statement is include_once('cookbook/quote.php'); (Note: I had trouble getting this script to work until I deleted the Main.Quotes file that was included in the zip. I then created Main.Quotes using the normal procedure for creating a new wikipage.) DiscussionRandomquote adds the markup (:randquote:) which will be replaced by a randomly chosen line from quotes.txt. The format for quotes.txt is one quote per line with pipes ( | ) used to denote line breaks within the quote. Each pipe will be replaced with <br> before the quote is inserted. You can see it in action at: http://www.hostgrabber.de Contributor
See alsoIf you want to avoid wikiword processing you may use the keep()? function: // the original code
// return "<div id=\"randquote\">$RandomQuote2</div>";
// adding the keep() function
return keep("<div id=\"randquote\">$RandomQuote2</div>");
-- Guillaume (2005-02-07) I liked this plugin so much, that i decided to migrate it to PmWiki 2.x -- Jens Rosenfeld (2005-01-08) Tiago Luis Bonamigo - Here is my update // Script: Copyright 2004 Dave Noonan, DaveNoonan@ThunderBunny.org
// 2004-02-15
// Update for PmWiki 2.x needs
//
// 2005-01-08 by Jens Rosenfeld, webmaster[at]hostgrabber.de
// Tested with PmWiki 2.0 Beta 14
//
//Changes made by Tiago Luis Bonamigo
//2005-01-08
//Tested with pmwiki-2.0.beta14
//
//=======================
// To make this script work, extract it in your pmwiki/cookbook directory.
// Then add the following line to config.php:
//
// include("cookbook/quote.php");
//
// Insert (:randquote:) as a markup to your wikipage.
// The markup will be replaced with the quote
//
//=======================
// Configuration:
//
// Fill a pmwiki page with quotes and start every quote with an asterisk.
// Put (:randquote:) inside every other page in pmwiki and get it replaced with a random quote.
//
//Changelog:
//
// Now you can choose a pmwiki page, full of quotes separated by an asterisk.
// We assume the new line will always be "2" exponencial, if you know what I mean.
// Changed the markup to be (:randquote:).
// That's all folks!!!
// Function to get a random line out of text file and sub <br> for | with a
// div named randquote around it.
function f_RandomQuote() {
$QuoteFile = "wiki.d/Main.Quotes";
$Quotes = fopen($QuoteFile, "r");
$conteudo = fread($Quotes, filesize ($QuoteFile));
fclose ($Quotes);
$arrConteudo = explode("\n",$conteudo);
foreach($arrConteudo as $linha)
if(substr($linha,0,6) == "text=*") {
$arrQuotes = substr($linha,6);
$arrQuotes = str_replace("2","<BR>",$arrQuotes);// have to change the first
// position on str_replace,
// to be "2" exponential.
$arrQuotes = explode("*",$arrQuotes);
}
srand( (double)microtime() * 1000000 );
shuffle($arrQuotes);
return "<div id=\"randquote\">$arrQuotes[0]</div>";
} // Pointer to the function
$randQuote =& f_RandomQuote();
// Add (:randquote:) markup that will be replaced with the quote
Markup("randquote","directives","/\\(:randquote:\\)/",$randQuote);
I wrote it slightly differently, as I like the idea to separate the quotes by "*", the reason being that the quote page then displays nicely as a bulleted list with one quote per bullet. To do this, I used a "**" to introduce a line break inside a quote. The code goes like this: Philippe? - 11/01/2005 foreach($arrConteudo as $linha)
if(substr($linha,0,6) == "text=*") {
$arrQuotes = substr($linha,6);
$arrQuotes = str_replace("**","<BR>",$arrQuotes);
$arrQuotes = explode("2*",$arrQuotes);
}
Replacing the 2 as an exponential 2, of course. This way, the quotes list can be like this:
What do you think ? I like it a lot as well (the version above), but I have a problem in that it still interprets wiki words, but does not interpret wiki markups (in particular those used to prevent interpretation :) ). Does anyone have a solution for this ? Philippe? - 11/01/2005 The answer to your problem is that the quotes are extracted from a pmwiki page without passing through pmwiki markup processing, just the "find & link" one. Obvious?! I know... CarlosAB OK, thanks for the explanation, any way around this ? Philippe? - 13/01/2005 Great Idea, Tiago. That makes things much more easier! -- Jens Rosenfeld (2005-01-08) Daniel Scheibler (2005-01-15): Changes:
important: variable configuration has to be done before include_once("cookbook/quote.php"); updated source: <?php
// Script: Copyright 2004 Dave Noonan, DaveNoonan@ThunderBunny.org
// 2004-02-15
//
// Update for PmWiki 2.x needs
// 2005-01-08 by Jens Rosenfeld, webmaster[at]hostgrabber.de
// Tested with PmWiki 2.0 Beta 14
//
//=======================
// To make this script work, extract it in your pmwiki/cookbook directory.
// Then add the following line to config.php:
//
// include("cookbook/quote.php");
//
// Insert (:randquote:) as a markup to your wikipage.
// The markup will be replaced with the quote
//
//=======================
// Configuration:
//
// Fill a pmwiki page with quotes and start every quote with an asterisk.
// Put (:randquote:) inside every other page in pmwiki and get it replaced with a random quote.
//
//Changelog:
//
// Now you can choose a pmwiki page, full of quotes separated by an asterisk.
// We assume the new line will always be "".
// Changed the markup to be (:randquote:).
// That's all folks!!!
// ============== Changes by Daniel Scheibler <pmwiki@scheiby.de> <http://www.scheiby.de>(approve links)
// * change "2*" into "$Newline" to use wiki-specific newline character
// * insertion of a config variable $QuoteRemoveItemize to change between $Newline
// and $Newline followed by an *
// * change "<BR>" into "<br />" for HTML 4 Compatibility
// * meaning of config variable $QuoteFile changed; could now be changed in local.php
// * insetion of a config variable $QuoteLineDelimiter, which will be changed in <br />
// Function to get a random line out of text file and sub <br> for | with a
// div named randquote around it.
SDV($QuoteFile, "Main.Quotes");
SDV($QuoteLineDelimiter, "**");
SDV($QuoteRemoveItemize, false);
function f_RandomQuote()
{
global $Newline;
global $QuoteFile;
global I have been using this with pmwiki-2.1.beta17 for a while with no unexpected results. ... I think we all know how that works though! (= Just a side note, but when you have this set as: $QuoteLineDelimiter = "[[<<]]"; $QuoteRemoveItemize = true; You can have entries like so: *"Do, or do not. There is no 'try'"[[<<]]~ Yoda *"The impossible is only a little bit harder."[[<<]]~ My Grandmother. *"When you're going through hell, keep going."[[<<]]~ Winston Churchill *"It is better to be hated for what you are than to be loved for what you are not."[[<<]]~ Andre Gide Which makes directly viewing the quote page(s) considerably easier. (= -- Feral January 06, 2006, at 09:38 PM
Perhaps this page should be redone, so it could be a little easier to read, and some of the outdated information can be deleted. I also had some problems with the zip file not extract properly. Would be better to just put up the php script and then give instructions on this page to create Main.Quotes and perhaps some sample text to cut and paste into that page. Caveman
|