[pLog-CVS] plog_plugins pluginhaiku.class.php,NONE,1.1
Brought to you by:
jondaley
From: <phu...@us...> - 2003-09-20 19:19:35
|
Update of /cvsroot/plog/plog_plugins In directory sc8-pr-cvs1:/tmp/cvs-serv32212 Added Files: pluginhaiku.class.php Log Message: added the files necessary for the 'haiku' plugin by Darren Greer, pl...@so... --- NEW FILE: pluginhaiku.class.php --- <?php include_once( "pluginbase.class.php" ); include_once( "pluginmanager.class.php" ); /** * Implementation of a very simple plugin file. */ class PluginHaiku extends PluginBase { function PluginHaiku() { $this->PluginBase(); $this->desc = " This plugin will generate a random Haiku<br/> <br/> Usage:<br/> To Display The Haiku: {\$haiku->getHaiku()}<br/><br/> To Display The Possible Permutations: {\$haiku->getHaikuPermutations()}<br/> {\$haiku->getHaikuStats()}<br/> "; $this->author = "Darren Greer"; // connect to the database $this->connectDb(); } function getHaiku() { // we need to take into account that plog has definable // prefixes for the database // so it is not sure that the user will have chosen 'plog_' // as the prefix... could be anything else!! $config = new Config(); $dbPrefix = $config->getValue( "db_prefix" ); $this->db->debug=true; // First 5 syllable line $query = "SELECT * FROM {$dbPrefix}haiku where haiku_syl=5 order by rand() LIMIT 1"; $result = $this->db->Execute( $query ); if( !$result ) { return false; } $row=$result->FetchRow(); extract($row); $return = "<i> $haiku_text </i><b> <=> </b>"; // 7 syllable line $query = "SELECT * FROM {$dbPrefix}haiku where haiku_syl=7 order by rand() LIMIT 1"; $result = $this->db->Execute( $query ); if( !$result ) { return false; } $row=$result->FetchRow(); extract($row); $return = $return . "<i> $haiku_text </i><b> <=> </b>"; // Second 5 syllable line $query = "SELECT * FROM {$dbPrefix}haiku where haiku_syl=5 order by rand() LIMIT 1"; $result = $this->db->Execute( $query ); if( !$result ) { return false; } $row=$result->FetchRow(); extract($row); $return = $return . "<i> $haiku_text </i>"; return $return; } function getHaikuPermutations() { // we need to take into account that plog has definable // prefixes for the database // so it is not sure that the user will have chosen 'plog_' // as the prefix... could be anything else!! $config = new Config(); $dbPrefix = $config->getValue( "db_prefix" ); // Get Possible Combinations $query = "SELECT count(*) as count5 FROM {$dbPrefix}haiku where haiku_syl=5"; $result = $this->db->Execute( $query ); if( !$result ) { return false; } $row=$result->FetchRow(); extract($row); $query = "SELECT count(*) as count7 FROM {$dbPrefix}haiku where haiku_syl=7"; $result = $this->db->Execute( $query ); if( !$result ) { return false; } $row=$result->FetchRow(); extract($row); $total_combs = ($count5 * $count7 * $count5); $return = "Permutations: <b>$total_combs</b>"; return $return; } function getHaikuStats() { // we need to take into account that plog has definable // prefixes for the database // so it is not sure that the user will have chosen 'plog_' // as the prefix... could be anything else!! $config = new Config(); $dbPrefix = $config->getValue( "db_prefix" ); // Get Possible Combinations $query = "SELECT count(*) as count5 FROM {$dbPrefix}haiku where haiku_syl=5"; $result = $this->db->Execute( $query ); if( !$result ) { return false; } $row=$result->FetchRow(); extract($row); $query = "SELECT count(*) as count7 FROM {$dbPrefix}haiku where haiku_syl=7"; $result = $this->db->Execute( $query ); if( !$result ) { return false; } $row=$result->FetchRow(); extract($row); $return = "5 Syllable: <b>$count5</b><br/>"; $return = $return . "7 Syllable: <b>$count7</b>"; return $return; } } PluginManager::registerPlugin( "haiku", "PluginHaiku" ); ?> |