Copyright (c) 1999-2009 Christophe DAVID

Permission to use, copy, modify, and distribute this software and its documentation under the terms of the GNU eneral Public License is hereby granted. No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.

See the GNU General Public License.
Files / miscellaneous

RandomQuoteWiki.php

<?php if (!defined('PmWiki')) exit();

/*  Copyright 2005 Christophe David (www.christophedavid.org)
    This file is RandomQuoteWiki.php; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published
    by the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This script adds two markups (:RandomQuoteWiki_quote:) and
    (:RandomQuoteWiki_author:) that contain a random quote stored
    in a pmwiki page (instead of a flat file that cannot be accessed
    by most users).

    The quotes must be structured like

    <quotes>
       <quote>
          <text>quote text 1</text>
          <author> quote author 1</author>
       </quote>
       <quote>
          <text>quote text 2</text>
          <author>quote author 2</author>
       </quote>
       ...
    </quotes>

    To use this script, simply copy it into the cookbook/ directory
    and add the following line to config.php or a per-page/per-group
    customization file.

        include_once('cookbook/RandomQuoteWiki.php');

   Then add something like
      || '''(:RandomQuoteWiki_quote:)''' ||
      || (:RandomQuoteWiki_author:) ||

   in you wiki page.

*/


################################################################################

SDV($RandomQuoteWikiPage, "$WorkDir/SiteData.RandomQuoteWiki");

# this should be $WikiDir instead of $WorkDir, but this "PageStore object"
# certainly desserves some more documentation.
# Anyway, by default they point to the same directory.

################################################################################
################################################################################
################################################################################

define(RANDOM_QUOTE_WIKI, '1.1');

$RandomQuoteWiki_quote  = '';
$RandomQuoteWiki_author = '';

$FileHandle = @fopen($RandomQuoteWikiPage, "rb");

if ($FileHandle != FALSE)
   {
   $FileContent = fread($FileHandle, filesize($RandomQuoteWikiPage));
   fclose($FileHandle);

   if (preg_match('|text=(.*)|', $FileContent, $matches) == 1)
      {
      $FileContent = preg_replace("'%([0-9A-Fa-f]{2})'e", "chr(hexdec('\\1'))", $matches[1]);

      if (preg_match("|<quotes>(.*?)</quotes>|s", $FileContent, $matches) == 1)
         {
         $QuotesData = $matches[1];
         $MatchesCount = preg_match_all("|<quote>(.*?)</quote>|s", $FileContent, $matches, PREG_PATTERN_ORDER);

         $QuoteData = $matches[1][rand(0, $MatchesCount - 1)];

         if (preg_match("|<text>\s*(.+?)\s*</text>|s", $QuoteData, $matches) == 1)
            {
            $RandomQuoteWiki_quote = $matches[1];
            if (preg_match("|<author>\s*(.+?)\s*</author>|s", $QuoteData, $matches) == 1)
               {
               $RandomQuoteWiki_author = $matches[1];
               }
            }
         }
      }
  }

Markup('RandomQuoteWiki_quote',  'fulltext', '/\(:RandomQuoteWiki_quote:\)/',  $RandomQuoteWiki_quote);
Markup('RandomQuoteWiki_author', 'fulltext', '/\(:RandomQuoteWiki_author:\)/', $RandomQuoteWiki_author);

?>
Files / miscellaneous

printer friendly view
PDF

   
Google
 
Web www.christophedavid.org