get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { ck_install(); } function ck_install() //Install the needed SQl entries. { global $table_prefix, $wpdb; $table_name = $table_prefix . "ck_karma"; $sql = 'CREATE TABLE `' . $table_name . '` (' //Add table . ' `ck_comment_id` VARCHAR(10) NOT NULL, ' . ' `ck_ips` BLOB NOT NULL, ' . ' `ck_rating` VARCHAR(4) NOT NULL' . ' )' . ' ENGINE = myisam;'; mysql_query($sql); $ck_result = mysql_query('SELECT comment_ID FROM ' . $table_prefix . 'comments'); //Put all IDs in our new table while($ck_row = mysql_fetch_array($ck_result, MYSQL_ASSOC)) //Wee loop { mysql_query("INSERT INTO $table_name (ck_comment_id, ck_ips, ck_rating) VALUES ('" . $ck_row['comment_ID'] . "', '', '0')"); } } function ck_get_karma($comment_id) { global $table_prefix; $table_name = $table_prefix . 'ck_karma'; $query = "SELECT ck_rating FROM `$table_name` WHERE ck_comment_id = $comment_id"; $result = mysql_query($query); if(!$result) { return('error|1'); } else { if($row = mysql_fetch_assoc($result)) { $karma = $row['ck_rating']; } else { return('error'); } if($karma < 0) { $karma = '-'. $karma; } else { $karma = '+'. $karma; } return $karma; } } function ck_comment_posted($ck_comment_id) //When comment posted this executes { global $table_prefix, $wpdb; $table_name = $table_prefix . "ck_karma"; mysql_query("INSERT INTO $table_name (ck_comment_id, ck_ips, ck_rating) VALUES ('" . $ck_comment_id . "', '" . getenv("REMOTE_ADDR") . "', '0')"); //Adds the new comment ID into our made table, with the users IP } function ck_display_karma() { $plugin_path = get_bloginfo('url').'/wp-content/plugins/ck-karma/'; $ck_link = str_replace('http://', '', get_bloginfo('url')); $ck_comment_ID = get_comment_ID(); $ck_comment_karma = ck_get_karma($ck_comment_ID); global $table_prefix, $wpdb; $table_name = $table_prefix . "ck_karma"; $ck_sql = "SELECT ck_ips FROM `$table_name` WHERE ck_comment_id = $ck_comment_ID"; $ck_result = mysql_query($ck_sql); if(!$ck_result) { mysql_error(); } if(!$ck_row = mysql_fetch_array($ck_result, MYSQL_ASSOC)) { mysql_error(); } if(strstr($ck_row['ck_ips'], getenv("REMOTE_ADDR"))) { echo(" "); } else { //Use onClick for the image instead, fixes the style link underline problem as well. echo(" \"Add "); echo("\"Subtract"); //Phew } echo "  {$ck_comment_karma}"; } ?>