Thread: [pLog-CVS] plog_plugins/plugins pluginkarma.class.php,1.2,1.3
Brought to you by:
jondaley
From: Oscar R. <phu...@us...> - 2004-03-20 16:08:14
|
Update of /cvsroot/plog/plog_plugins/plugins In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2595/plugins Modified Files: pluginkarma.class.php Log Message: first beta version, works quite well... Index: pluginkarma.class.php =================================================================== RCS file: /cvsroot/plog/plog_plugins/plugins/pluginkarma.class.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** pluginkarma.class.php 14 Mar 2004 15:46:28 -0000 1.2 --- pluginkarma.class.php 20 Mar 2004 15:58:13 -0000 1.3 *************** *** 5,8 **** --- 5,9 ---- include_once( PLOG_CLASS_PATH."class/net/requestgenerator.class.php" ); include_once( PLOG_CLASS_PATH."class/karma/karmalib.class.php" ); + include_once( PLOG_CLASS_PATH."class/data/integervalidator.class.php" ); define( "PLUGIN_KARMA_SHOW_CONFIGURATION_PAGE", "configurePage" ); *************** *** 17,20 **** --- 18,23 ---- var $negativeKarmaThreshold; var $trackVoters; + var $minNumVotes; + var $defaultCoefficient; var $_result; *************** *** 43,48 **** positive score and a link showing the negative score, the following bit of code would do:<br/><br/><b> ! <a href=\"{\$karma->getKarmaUrl(\$post,1)}\">+{\$karma->getPositiveKarma($post)}</a><br/> ! <a href=\"{\$karma->getKarmaUrl(\$post,2)}\">-{\$karma->getNegativeKarma($post)}</a> </b><br/><br/> The {\$karma->getKarmaUrl(\$post,X)} method takes a post as a parameter --- 46,51 ---- positive score and a link showing the negative score, the following bit of code would do:<br/><br/><b> ! <a href=\"{\$karma->getKarmaUrl(\$post,1)}\">+{\$karma->getPositiveKarma(\$post)}</a><br/> ! <a href=\"{\$karma->getKarmaUrl(\$post,2)}\">-{\$karma->getNegativeKarma(\$post)}</a> </b><br/><br/> The {\$karma->getKarmaUrl(\$post,X)} method takes a post as a parameter *************** *** 65,71 **** // make sure that the tables exist and that they // have the right scheme ! $this->connectDb(); ! ! $this->createKarmaTables(); // retrieve our settings --- 68,73 ---- // make sure that the tables exist and that they // have the right scheme ! $k = new KarmaScores(); ! $k->createKarmaTables(); // retrieve our settings *************** *** 79,138 **** if( $this->negativeKarmaThreshold == "" ) $this->negativeKarmaThreshold = 100; - print($this->blogSettings->getValue("plugin_karma_track_voters")); $this->trackVoters = $this->blogSettings->getValue( "plugin_karma_track_voters" ); if( $this->trackVoters == "" ) $this->trackVoters = false; - } - - function getPrefix() - { - $config =& Config::getConfig(); - $prefix = $config->getValue( "db_prefix" ); - - return $prefix; - } - - function checkTable( $tableName, $tableSchema ) - { - //$config = new Config(); - //$dbPrefix = $config->getValue( "db_prefix" ); - $dbPrefix = $this->getPrefix(); - $tableName = $dbPrefix.$tableName; - - // create the data dictionary and create the table if necessary - $dict = NewDataDictionary( $this->db ); - $sqlArray = $dict->ChangeTableSQL( $tableName, $tableSchema ); - $result = $dict->ExecuteSQLArray( $sqlArray ); - - if( $result == 0 ) - $this->_desc = "There was an error initializing the tables."; - } - - /** - * Uses ADOdb data dictionaries functionality to create the - * tables needed for this plugin - */ - function createKarmaTables() - { - $table1 = "karma_scores"; - $fields1 = " - blog_id I(10) NOTNULL, - article_id I(10) NOTNULL, - positive_karma I(5) NOTNULL, - negative_karma I(5) NOTNULL, - last_vote date T(14) DEFDATE - "; - $this->checkTable( $table1, $fields1 ); ! // create the table to keep track of the voters, so that people cannot vote ! // more than once ! $table2 = "karma_voters"; ! $fields2 = " ! article_id I(10) NOTNULL, ! client_ip C(16) NOTNULL, ! date T(14) DEFDATE ! "; ! $this->checkTable( $table2, $fields2 ); ! return true; } --- 81,92 ---- if( $this->negativeKarmaThreshold == "" ) $this->negativeKarmaThreshold = 100; $this->trackVoters = $this->blogSettings->getValue( "plugin_karma_track_voters" ); if( $this->trackVoters == "" ) $this->trackVoters = false; ! $this->minNumVotes = $this->blogSettings->getValue( "plugin_karma_minimum_amount_votes" ); ! if( $this->minNumVotes == "" ) $this->minNumVotes = PLUGIN_KARMA_DEFAULT_MIN_VOTES; ! $this->defaultCoefficient = $this->blogSettings->getValue( "plugin_karma_scoring_coefficient" ); ! if( $this->defaultCoefficient == "" ) $this->defaultCoefficient = PLUGIN_KARMA_DEFAULT_COEFFICIENT; } *************** *** 141,161 **** */ function getPositiveKarma( $post ) ! { ! $postId = $post->getId(); ! $prefix = $this->getPrefix(); ! ! $query = "SELECT * FROM {$prefix}karma_scores WHERE article_id = ".$post->getId(); ! ! $result = $this->db->Execute( $query ); ! ! if( !$result ) ! return 0; ! ! if( $result->RecordCount() == 0) ! return 0; ! ! $row = $result->FetchRow(); ! return $row["positive_karma"]; } --- 95,103 ---- */ function getPositiveKarma( $post ) ! { ! $k = new KarmaScores(); ! $result = $k->getPostKarma( $this->blogInfo->getId(), $post->getId()); ! return $result["positive_karma"]; } *************** *** 165,184 **** function getNegativeKarma( $post ) { ! $postId = $post->getId(); ! $prefix = $this->getPrefix(); ! ! $query = "SELECT * FROM {$prefix}karma_scores WHERE article_id = ".$post->getId(); ! ! $result = $this->db->Execute( $query ); ! ! if( !$result ) ! return 0; ! ! if( $result->RecordCount() == 0) ! return 0; ! ! $row = $result->FetchRow(); ! return $row["negative_karma"]; } --- 107,114 ---- function getNegativeKarma( $post ) { ! $k = new KarmaScores(); ! $result = $k->getPostKarma( $this->blogInfo->getId(), $post->getId()); ! return $result["negative_karma"]; } *************** *** 216,219 **** --- 146,163 ---- $negativeThreshold = $params->getValue( "negativeThreshold" ); $trackVoters = $params->getValue( "trackVoters" ); + + // check the scoring coefficient + $scoringCoefficient = $params->getValue( "scoring" ); + $val = new IntegerValidator( $scoringCoefficient ); + if( !$val->validate() || $scoringCoefficient < 0 ) + $scoringCoefficient = PLUGIN_KARMA_DEFAULT_COEFFICIENT; + + // check the minimum amount of points needed before the algorithm kicks in + // and starts disabling articles :) + $minimumVotes = $params->getValue( "minVotes" ); + $val2 = new IntegerValidator( $minimumVotes ); + if( !$val2->validate() || $minimumVotes < 0 ) + $minimumVotes = PLUGIN_KARMA_DEFAULT_MIN_VOTES; + //if( $trackVoters == "" || $trackVoters == null ) $trackVoters = false; //else $trackVoters = true; *************** *** 223,226 **** --- 167,172 ---- $this->blogSettings->setValue( "plugin_karma_negative_threshold", $negativeThreshold ); $this->blogSettings->setValue( "plugin_karma_track_voters", $trackVoters ); + $this->blogSettings->setValue( "plugin_karma_scoring_coefficient", $scoringCoefficient ); + $this->blogSettings->setValue( "plugin_karma_minimum_amount_votes", $minimumVotes ); //print_r($this->blogSettings); *************** *** 257,262 **** // their karma scores // It will only show their subject and the scores $karmas = new KarmaScores(); ! $modDownArticles = $karmas->getModeratedDownArticles( $this->blogInfo->getId()); $message = "<h2>Karma Plugin Moderated Down Articles</h2>"; --- 203,210 ---- // their karma scores // It will only show their subject and the scores + $minNumVotes = $this->blogSettings->getValue( "plugin_karma_minimum_amount_votes" ); + $coef = $this->blogSettings->getValue( "plugin_karma_scoring_coefficient" ); $karmas = new KarmaScores(); ! $modDownArticles = $karmas->getModeratedDownArticles( $this->blogInfo->getId(), $minNumVotes, $coef ); $message = "<h2>Karma Plugin Moderated Down Articles</h2>"; *************** *** 295,303 **** $message .=" checked=\"checked\""; $message .=" /> Track voters (users cannot vote more than once)<br/><br/> ! <!--If the difference between positive karma and negative karma votes is higher than this ! threshold, the article will be removed from the page and it will only be possible to ! access it via the 'Moderated down articles' page:<br/> ! <input type=\"text\" name=\"negativeThreshold\" value=\"".$this->negativeKarmaThreshold."\" />--> ! <br/><br/> <input type=\"submit\" name=\"Save\" value=\"Save\" /> <input type=\"hidden\" name=\"op\" value=\"updatePluginConfig\" /> --- 243,263 ---- $message .=" checked=\"checked\""; $message .=" /> Track voters (users cannot vote more than once)<br/><br/> ! Minimum number of votes needed before karma starts counting. This is to prevent ! that with just one vote an article can be disabled. If you set this to 100, then ! at least a total number of votes equalling 100 will be needed before the article is ! removed from the main page:<br/> ! <input type=\"text\" name=\"minVotes\" value=\"".$this->minNumVotes."\"/><br/><br/> ! Negative votes multiplier. How many more negative votes are needed before an article ! can be removed from the main page? This is done to give certain advantage to positive ! votes: <select name=\"scoring\"> ! <option value=\"1\""; ! if( $this->defaultCoefficient == "1" ) $message .=" selected=\"selected\" "; ! $message .= ">Exactly as many</option> ! <option value=\"1.5\""; ! if( $this->defaultCoefficient == "1.5" ) $message .=" selected=\"selected\" "; ! $message .= ">50% more</option> ! <option value=\"2\""; ! if( $this->defaultCoefficient == "2" ) $message .= " selected=\"selected\" "; ! $message .= ">Twice as many</option></select><br/><br/> <input type=\"submit\" name=\"Save\" value=\"Save\" /> <input type=\"hidden\" name=\"op\" value=\"updatePluginConfig\" /> |