get_config(PLUGIN_EVENT_COMMENTSPICE_CNAME_DBCONFIG); if (empty($dbversion)) $dbversion=0; if (!DbSpice::table_created('commentspice')) { // twitternames cant be longer than 15 referring to API docs. 20 for safety. nvarchar because of unicode names $q = "create table {$serendipity['dbPrefix']}commentspice (" . "commentid int(10) not null, " . "twittername nvarchar(20), " . "primary key (commentid)" . ")"; $result = serendipity_db_schema_import($q); if ($result !== true) { return; } $obj->set_config(PLUGIN_EVENT_COMMENTSPICE_CNAME_DBCONFIG, 1); } // Version 2 updates if ($obj->get_config((PLUGIN_EVENT_COMMENTSPICE_CNAME_DBCONFIG)<2)) { $q = "alter table {$serendipity['dbPrefix']}commentspice" . " add column promo_name nvarchar(200),". " add column promo_url nvarchar(250);"; serendipity_db_query($q); $obj->set_config(PLUGIN_EVENT_COMMENTSPICE_CNAME_DBCONFIG, 2); } // Version 3 updates if ($obj->get_config((PLUGIN_EVENT_COMMENTSPICE_CNAME_DBCONFIG)<3)) { $q = "CREATE INDEX IDX_COMMENTS_EMAIL" . " on {$serendipity['dbPrefix']}comments (email);"; serendipity_db_query($q); // if it already exists, it won't be created $obj->set_config(PLUGIN_EVENT_COMMENTSPICE_CNAME_DBCONFIG, 3); } } function countComments($email) { global $serendipity; if (empty($email)) return 0; $db_email = serendipity_db_escape_string($email); $q = "SELECT COUNT(*) AS commentcount FROM {$serendipity['dbPrefix']}comments WHERE email='$db_email'"; $row = serendipity_db_query($q, true); return $row['commentcount']; } function saveCommentSpice($commentid, $twittername, $promo_name, $promo_url) { global $serendipity; if (empty($commentid) || !is_numeric($commentid) || (empty($twittername) && empty($promo_name)) ) return true; $db_twittername = (empty($twittername)?'':serendipity_db_escape_string($twittername)); $db_promo_name = (empty($promo_name)?'':serendipity_db_escape_string($promo_name)); $db_promo_url = (empty($promo_url)?'':serendipity_db_escape_string($promo_url)); $sql = "INSERT INTO {$serendipity['dbPrefix']}commentspice (commentid, twittername, promo_name, promo_url) "; if (empty($promo_name)) $sql .= " VALUES ($commentid, '$db_twittername', NULL, NULL)"; elseif (empty($twittername)) $sql .= " VALUES ($commentid, NULL, '$db_promo_name', '$db_promo_url')"; else $sql .= " VALUES ($commentid, '$db_twittername', '$db_promo_name', '$db_promo_url')"; return serendipity_db_query($sql); } function loadCommentSpice($commentid) { global $serendipity; if (empty($commentid) || !is_numeric($commentid)) return false; $sql = "SELECT * FROM {$serendipity['dbPrefix']}commentspice WHERE commentid=$commentid"; $row = serendipity_db_query($sql, true); if (!is_array($row)) return false; return $row; } function deleteCommentSpice($commentid) { global $serendipity; if (empty($commentid) || !is_numeric($commentid)) return; $sql = "DELETE FROM {$serendipity['dbPrefix']}commentspice WHERE commentid=$commentid"; return serendipity_db_query($sql, true); } }