OSDN Git Service

定数名修正(nucleus/language/english.php)
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / KARMA.php
index 26ca7c3..eb36370 100755 (executable)
-<?php\r
-/**\r
-  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) \r
-  * Copyright (C) 2002-2005 The Nucleus Group\r
-  *\r
-  * This program is free software; you can redistribute it and/or\r
-  * modify it under the terms of the GNU General Public License\r
-  * as published by the Free Software Foundation; either version 2\r
-  * of the License, or (at your option) any later version.\r
-  * (see nucleus/documentation/index.html#license for more info)\r
-  *\r
-  * Class representing the karma votes for a certain item\r
-  *\r
-  * $Id: KARMA.php,v 1.3 2005-03-15 07:57:29 kimitake Exp $\r
-  * $NucleusJP$\r
-  */\r
-class KARMA {\r
-       \r
-       // id of item about which this object contains information\r
-       var $itemid;\r
-       \r
-       // indicates if the karma vote info has already been intialized from the DB\r
-       var $inforead;\r
-       \r
-       // amount of positive/negative votes\r
-       var $karmapos;\r
-       var $karmaneg;\r
-       \r
-       function KARMA($itemid, $initpos = 0, $initneg = 0, $initread = 0) {    \r
-               // itemid\r
-               $this->itemid = intval($itemid);\r
-\r
-               // have we read the karma info yet?\r
-               $this->inforead = intval($initread);    \r
-               \r
-               // number of positive and negative votes\r
-               $this->karmapos = intval($initpos);\r
-               $this->karmaneg = intval($initneg);\r
-       }\r
-       \r
-       function getNbPosVotes() {\r
-               if (!$this->inforead) $this->readFromDatabase();\r
-               return $this->karmapos;\r
-       }\r
-       function getNbNegVotes() {\r
-               if (!$this->inforead) $this->readFromDatabase();\r
-               return $this->karmaneg;\r
-       }\r
-       function getNbOfVotes() {\r
-               if (!$this->inforead) $this->readFromDatabase();\r
-               return ($this->karmapos + $this->karmaneg);\r
-       }\r
-       function getTotalScore() {\r
-               if (!$this->inforead) $this->readFromDatabase();\r
-               return ($this->karmapos - $this->karmaneg);\r
-       }\r
-       \r
-       function setNbPosVotes($val) {\r
-               $this->karmapos = intval($val);\r
-       }\r
-       function setNbNegVotes($val) {\r
-               $this->karmaneg = intval($val);\r
-       }\r
-\r
-\r
-       // adds a positive vote\r
-       function votePositive() {\r
-               $newKarma = $this->getNbPosVotes() + 1;\r
-               $this->setNbPosVotes($newKarma);\r
-               $this->writeToDatabase();\r
-               $this->saveIP();\r
-       }\r
-       \r
-       // adds a negative vote\r
-       function voteNegative() {\r
-               $newKarma = $this->getNbNegVotes() + 1; \r
-               $this->setNbNegVotes($newKarma);                \r
-               $this->writeToDatabase();               \r
-               $this->saveIP();\r
-       }\r
-\r
-\r
-\r
-       // these methods shouldn't be called directly\r
-       function readFromDatabase() {\r
-               $query = 'SELECT ikarmapos, ikarmaneg FROM '.sql_table('item').' WHERE inumber=' . $this->itemid;\r
-               $res = sql_query($query);\r
-               $obj = mysql_fetch_object($res);\r
-               \r
-               $this->karmapos = $obj->ikarmapos;\r
-               $this->karmaneg = $obj->ikarmaneg;              \r
-               $this->inforead = 1;\r
-       }\r
-               \r
-       \r
-       function writeToDatabase() {\r
-               $query = 'UPDATE '.sql_table('item').' SET ikarmapos=' . $this->karmapos . ', ikarmaneg='.$this->karmaneg.' WHERE inumber=' . $this->itemid;\r
-               sql_query($query);\r
-       }\r
-       \r
-       // checks if a vote is still allowed for an IP\r
-       function isVoteAllowed($ip) {\r
-               $query = 'SELECT * FROM '.sql_table('karma')." WHERE itemid=$this->itemid and ip='".addslashes($ip)."'";\r
-               $res = sql_query($query);\r
-               return (mysql_num_rows($res) == 0);\r
-       }\r
-       \r
-       // save IP in database so no multiple votes are possible\r
-       function saveIP() {\r
-               $query = 'INSERT INTO '.sql_table('karma').' (itemid, ip) VALUES ('.$this->itemid.",'".addslashes(serverVar('REMOTE_ADDR'))."')";\r
-               sql_query($query);\r
-       }\r
-}\r
-\r
-?>\r
+<?php
+/*
+ * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
+ * Copyright (C) 2002-2009 The Nucleus Group
+ *
+ * This program is free software; 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.
+ * (see nucleus/documentation/index.html#license for more info)
+ */
+/**
+ * Class representing the karma votes for a certain item
+ *
+ * @license http://nucleuscms.org/license.txt GNU General Public License
+ * @copyright Copyright (C) 2002-2009 The Nucleus Group
+ * @version $Id$
+ * $NucleusJP: KARMA.php,v 1.5 2006/07/17 20:03:44 kimitake Exp $
+ */
+class KARMA {
+
+       // id of item about which this object contains information
+       var $itemid;
+
+       // indicates if the karma vote info has already been intialized from the DB
+       var $inforead;
+
+       // amount of positive/negative votes
+       var $karmapos;
+       var $karmaneg;
+
+       function KARMA($itemid, $initpos = 0, $initneg = 0, $initread = 0) {
+               // itemid
+               $this->itemid = intval($itemid);
+
+               // have we read the karma info yet?
+               $this->inforead = intval($initread);
+
+               // number of positive and negative votes
+               $this->karmapos = intval($initpos);
+               $this->karmaneg = intval($initneg);
+       }
+
+       function getNbPosVotes() {
+               if (!$this->inforead) $this->readFromDatabase();
+               return $this->karmapos;
+       }
+       function getNbNegVotes() {
+               if (!$this->inforead) $this->readFromDatabase();
+               return $this->karmaneg;
+       }
+       function getNbOfVotes() {
+               if (!$this->inforead) $this->readFromDatabase();
+               return ($this->karmapos + $this->karmaneg);
+       }
+       function getTotalScore() {
+               if (!$this->inforead) $this->readFromDatabase();
+               return ($this->karmapos - $this->karmaneg);
+       }
+
+       function setNbPosVotes($val) {
+               $this->karmapos = intval($val);
+       }
+       function setNbNegVotes($val) {
+               $this->karmaneg = intval($val);
+       }
+
+
+       // adds a positive vote
+       function votePositive() {
+               $newKarma = $this->getNbPosVotes() + 1;
+               $this->setNbPosVotes($newKarma);
+               $this->writeToDatabase();
+               $this->saveIP();
+       }
+
+       // adds a negative vote
+       function voteNegative() {
+               $newKarma = $this->getNbNegVotes() + 1;
+               $this->setNbNegVotes($newKarma);
+               $this->writeToDatabase();
+               $this->saveIP();
+       }
+
+
+
+       // these methods shouldn't be called directly
+       function readFromDatabase() {
+               $query = 'SELECT ikarmapos, ikarmaneg FROM '.sql_table('item').' WHERE inumber=' . $this->itemid;
+               $res = sql_query($query);
+               $obj = mysql_fetch_object($res);
+
+               $this->karmapos = $obj->ikarmapos;
+               $this->karmaneg = $obj->ikarmaneg;
+               $this->inforead = 1;
+       }
+
+
+       function writeToDatabase() {
+               $query = 'UPDATE '.sql_table('item').' SET ikarmapos=' . $this->karmapos . ', ikarmaneg='.$this->karmaneg.' WHERE inumber=' . $this->itemid;
+               sql_query($query);
+       }
+
+       // checks if a vote is still allowed for an IP
+       function isVoteAllowed($ip) {
+               $query = 'SELECT * FROM '.sql_table('karma')." WHERE itemid=$this->itemid and ip='".addslashes($ip)."'";
+               $res = sql_query($query);
+               return (mysql_num_rows($res) == 0);
+       }
+
+       // save IP in database so no multiple votes are possible
+       function saveIP() {
+               $query = 'INSERT INTO '.sql_table('karma').' (itemid, ip) VALUES ('.$this->itemid.",'".addslashes(serverVar('REMOTE_ADDR'))."')";
+               sql_query($query);
+       }
+}
+
+?>
\ No newline at end of file